local iori_run_action = class('iori_run_action',function()
	return display.newNode()
end)

function iori_run_action:ctor()
	self:pos(display.cx,display.cy)
	self:setRotation(90)
	display.newSolidCircle(8,{color = cc.c4f(0.0,0,1.0,0.8)}):addTo(self)
	local frames = display.newFrames("iori2_%03d.png", 18, 8)

	--if not self.iori then print('... not have iori_run_action iori ...') end

	self.iori = cc.Sprite:createWithSpriteFrame(frames[1]):addTo(self)
	--self.iori:setTag(3)
	--self.iori:pos(display.cx,display.cy)
	self.Shape = self.Shape or {}
	self.body = cc.PhysicsBody:create()
	self.body:setTag(110)
	--self.body:retain()
	self.iori:setPhysicsBody(self.body)
	--self.body:setCategoryBitmask(1)
	--self.body:setCollisionBitmask(0x80)
	--self.body:setContactTestBitmask(1)
	--self.body:setDynamic(false) 				--设置为静态物体
	--self.body:setGravityEnable(false)			--设置是否受重力影响
	
	local spriteWidth = self.iori:getContentSize().width
	local spriteHeight = self.iori:getContentSize().height

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(84,122) ,cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-84)/2 - 100,(spriteHeight-122)/2 -8))
	---[[
	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(86,116),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-86)/2 - 92,(spriteHeight-116)/2 - 10))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(80,82),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-80)/2 - 96,(spriteHeight-82)/2 - 42))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(80,112),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-80)/2 - 100,(spriteHeight-112)/2 - 16))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(80,118),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-80)/2 - 104,(spriteHeight-118)/2 - 8))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(86,118),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-86)/2 - 96,(spriteHeight-118)/2 - 10))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(82,82),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-82)/2 - 96,(spriteHeight-82)/2 - 45))

	self.Shape[#self.Shape+1] = cc.PhysicsShapeBox:create(cc.size(78,114),cc.PHYSICSSHAPE_MATERIAL_DEFAULT , cc.p((spriteWidth-78)/2 - 104,(spriteHeight-114)/2 - 16))

	for i=1,8 do
		self.Shape[i]:setTag(i)
		self.Shape[i]:retain() 			--需要retain否则下一帧无法改变shape
		self.Shape[i]:setCategoryBitmask(4)
		self.Shape[i]:setCollisionBitmask(1)
		self.Shape[i]:setContactTestBitmask(3)
	end

	--]]

	--self.body:addShape(self.Shape[1])
	local once = false
	local function replaceShape(number)
		local tag = number == 1 and 8 or number - 1
		--local shape = self.body:getShape(tag)
		self.body:removeShape(tag)
		self.body:addShape(self.Shape[number])
		--self.Shape[number]:setTag(110)
		--self.body:setCategoryBitmask(1)
		--self.body:setCategoryBitmask(1)
		--self.body:setContactTestBitmask(0xffffffff)
		--if not once then printf('iori_run setContactTestBitmask=%d',self.body:getContactTestBitmask()) once=true end
	end

	local seq = cc.Sequence:create(
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(2) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(3) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(4) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(5) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(6) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(7) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(8) end),
			cc.DelayTime:create(0.1),
			cc.CallFunc:create(function() replaceShape(1) end)
		)

	local spawn = cc.Spawn:create({cc.Animate:create(display.newAnimation(frames, 0.8/#frames)),seq})
	self.iori:runAction(cc.RepeatForever:create(spawn))--cc.Animate:create(display.newAnimation(frames, 0.8/#frames))))
	--self.iori:playAnimationForever(display.newAnimation(frames, 0.8/#frames))

	--[[
	-- 测试replaceShape函数
	--local num = 2
	local buttom = cc.ui.UIPushButton.new({normal = 'CloseNormal.png',pressed = 'CloseSelected.png'},{scale9=true})
				:onButtonClicked(function(event)
					print('... onButtonClicked ...')
					--replaceShape(num)
					--num = num + 1
				end)
				:addTo(self)
				:pos(display.cx,display.cy+200)
	]]

	--printf('iori_run.body:setCategoryBitmask = %d',self.body:getCategoryBitmask())
end

return iori_run_action